<%@page import="java.util.*"%>
<%@page import="java.text.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%
    String path = request.getContextPath(); 
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+path+ "/"; 
%>
<!DOCTYPE HTML>
<html>
<head>
	<base href="<%=basePath%>">
	<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
	<title>司机端行程反馈列表</title>
	<link rel="stylesheet" href="plugin/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
	<link rel="stylesheet" href="css/bootstrap-datetimepicker.css" />
    <link rel="stylesheet" href="plugin/bootstrap-table/dist/bootstrap-table.css">
<style type="text/css">

ul{
    list-style-type: none;
}
 .breadcrumb{
          padding: 21px 25px;
       }    
  a {
    color: #2a3f54;
}      
</style>

</head>
<body>
    <div class="row base-margin" id="query">
        <ul class="breadcrumb">
				<li style="padding-left: 15px"><i class="icon-home home-icon"></i> <a href="javascript:void(0)">System Settings(系统设置)</a>
				</li>
				<li class="active">
				<a href="view/sys/user_feedback_list.jsp">Rider’s Review(行车反馈列表)</a></li>
        </ul>
        
        <form class="form-inline" role="form" style="float: left; width: 100%" method="post" id="queryForm">
           <input type="hidden" id='tkIndex' /> <input type="hidden" id='tkLoadIndex' />
           <div class="form-group">  
                <label for="bName">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Registration time(注册时间):</label> 
                <input type="text" class="form-control input-append form_date"  id="startTime" />-
                <input type="text" class="form-control input-append form_date"   id="endTime" />
            </div>   
             <div class="form-group">  
                <label for="bName">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Riders Account(反馈账号):</label> 
                <input type="text" class="form-control"  id="account"  />
            </div>  
             <div class="form-group">
                <label for="bName">Status(处理状态):</label> 
                 <select id='msgstat' class="form-control" >
                   <option value="">Total</option>
                    <option value="0">Not Complete</option>
                    <option value="3">Complete</option>
                 </select>
            </div> 
            <div class="form-group">
                <button type="button" id="queryBtn" onclick="doQuery1('demo-table',queryParams1());" class="btn btn-primary">Search(搜索)</button>
            </div> 
        </form>
    </div>
    <div class="container" style="width: 100%;margin-top:15px">
        <table id="demo-table">
        </table>
    </div>
</body>
	<!-- 加载需要的js -->
	<script src="js/jquery-3.2.1.min.js"></script>
	<script src="plugin/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
	<script src="js/jquery-bootstrap-pagination.js"></script>
	<script src="plugin/bootstrap-table/dist/bootstrap-table.min.js"></script>
	<script src="plugin/bootstrap-table/dist/locale/bootstrap-table-zh-CN.min.js"></script>
	<!--时间  -->
	<script src="js/bootstrap-datetimepicker.js"></script>
	<script src="js/bootstrap-datetimepicker.zh-CN.js"></script>
	<script src="js/common.js"></script>
	<script src="plugin/layer/layer.js"></script>
	<!-- 查询客户端ip使用 -->
	<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>  
	
	
	<script type="text/javascript" charset="utf-8">
	function jump(url){
		window.location.href=url;
	}
	$(function () {
		initPath("<%=basePath%>");
	    initTable('demo-table',queryParams,columns,"sugFeedback/getUserList");
	});
	
	   $('.form_date').datetimepicker({
	        minView: "month", //选择日期后，不会再跳转去选择时分秒 
	        language: 'zh-CN',
	        format: 'dd/mm/yyyy',
	        todayBtn:  1,
	        autoclose: 1,
	    });
var  columns= [ 
	  {  field : 'id',  title : 'Operation(操作)', align : 'center', valign : 'middle',formatter:function(value, row, index){
	    	 sessionStorage.setItem('driverFeeb'+index, JSON.stringify(row));//存值
	    	 if(row.msgstat==3||row.isRefund==1){//处理之后就不允许退款了
	    		 return ""
	    	 }else{
	    		 return "<a href='javascript:void(0);' style='color:blue' onclick='refundUser(\""+index+"\")'>Refund(退款)</a>&nbsp;&nbsp;&nbsp;<a  style='color:blue' href='javascript:void(0);' onclick='noDeductions(\""+row.id+"\")'>No Refund(不退款)</a>"
	    	 }
	     } },
	 { field : 'orderNo',  title : 'Order Number(订单号)',  align : 'center', valign : 'middle'},
	 { field : 'msgdate',  title : 'Review time(反馈时间)',  align : 'center', valign : 'middle',formatter:timeStamp2String },
	 { field : 'account',  title : 'Review Account(被反馈账号)',  align : 'center', valign : 'middle' },
	 { field : 'userfirstName',  title : 'Review Account(反馈账号)',  align : 'center', valign : 'middle' },
	 { field : 'msgcontent', title : 'Details(详细描述)', align : 'center', valign : 'middle' },
     {  field : 'imgs',  title : 'Photos(反馈图片)', align : 'center', valign : 'middle',formatter:function(value, row, index){
    	 var str="";
    	 if(value!=null){
    		var img= value.split(",");
    		for(var i in img){
    			str+="<img style='width:80px;height:80px' src='"+img[i]+"'/>";
    		}
    	 }
    	 return str;
     } },
     {  field : 'msgstat',  title : 'Status(处理状态)', align : 'center', valign : 'middle',formatter:function(value, row, index){
    	 var str="";
    	 if(value==0){
    		 str="Not Complete";
    	 }else if(value==3){
    		 str="Complete"; 
    	 }
    	 return "<a style='color:blue' onclick='pop("+row.id+","+value+")'>"+str+"</a>";
     }  },
     {  field : 'amountOfDeductions',  title : 'Debit Amount(扣款金额)', align : 'center', valign : 'middle' },
     {  field : 'remark',  title : 'Notes(备注)', align : 'center', valign : 'middle'},
	 ];
	 
	 //扣款 更新订单状态 扣取清洁费 更新订单的清洁费状态 清洁费 且 调用支付扣款
	 function refundUser(index){
		 var account="";var orderNo="";var remark="";var imgs="";
		 var amountOfDeductions="";var debitAccount="";var msgdate="";var id="";
		 var row = JSON.parse(sessionStorage.getItem('driverFeeb'+index));//取值
		 if(row!=null){
			 account=row.account==null?"":row.account;orderNo=row.orderNo==null?"":row.orderNo;remark=row.remark==null?"":row.remark;msgdate=timeStamp2String(row.msgdate);
			 imgs=row.imgs==null?"":row.imgs;var img="";
			 if(imgs==""||imgs==null){
			 }else{
				 var im =imgs.split(","); 
					for(var i in im){
						img+="<img style='width:80px;height:80px;margin-left:3px' src='"+im[i]+"'/>";
					}
			 }
			 imgs=img;
			 id=row,id;
			 amountOfDeductions=row.amountOfDeductions==null?"":row.amountOfDeductions;debitAccount=row.debitAccount==null?"":row.debitAccount;id=row.id==null?"":row.id;
		 }
		 
		 var str=' <form id="debit" ><table style="margin-left:10px">'+
         '  <tr class="padtr"><td class="pad" >Refund way(退费方式):</td> '+
         '<td><input name="refund_party" type="radio" value="1" onclick="onClicktk()"/>Cash back(退现金)<input name="refund_party" type="radio" value="2" onclick="onClicktk()"/>return a coupon(返优惠劵)</select></td>'+
         '</tr>'+
         '  <tr class="padtrs" id="tkje"><td class="pad" >Refund amount (aud)(退款金额（澳元）:</td> '+
         '<td><input name="id" type="hidden" value="'+id+'" /><input type="number"   oninput="reg(\'refund_amout\')"  id="refund_amout"/></td>'+
         '</tr>'+
         '  <tr class="padtrs"><td class="pad" >Refund way(退费方式):</td> '+
         '<td>(way to return)原路返回</td>'+
         '</tr>'+
         '  <tr class="padtr" id="fjje" style="display:none"><td class="pad">amount(返劵金额):</td> '+
         '<td><input type="number"   oninput="reg(\'refund_amout1\')"  id="refund_amout1"/></td>'+
         '</tr>'+
         /* '  <tr class="padtrs"><td class="pad" >Refund party(退款方):</td> '+
         '<td><select id="refund_party"><option value="1">平台补助</option><option value="2">司机扣除</option></select></td>'+
         '</tr>'+ */
         '  <tr class="padtrs"><td class="pad">refund reason(退款原因):</td> '+
         '<td><textarea id="refund_reason"  rows="3" cols="20"></textarea></td>'+
         '</tr>'+
         ' <tr align="center" class="padtr"><td colspan="5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
         ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
         ' <button type="button" onclick="sure()" class="btn btn-info btn1">&nbsp;&nbsp;Save&nbsp;&nbsp;</button>'+
         '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
         '<button type="button"  onclick="cacel()"class="btn  btn1" style="border: 1px solid;">&nbsp;Cancel&nbsp;&nbsp;</button></td></tr></table></form>';
		var tkIndex= layer.open({
			  type: 1,
			  title: "Refund",
			  skin: 'layui-layer-rim', //加上边框
			  area: ['620px', '380px'], //宽高
			  content: str
			});
		$('#tkIndex').val(tkIndex);
		 var selects=document.getElementsByName("refund_party");  
		 for (var i=0; i<selects.length; i++){  
		        if (selects[i].value=="1") {  
		            selects[i].checked= true;  
		            break;  
		        }  
		    }  
	 }
	 
	 //点击退款方式
	 function onClicktk(){
		var types= $("input[name='refund_party']:checked").val();
		if(types==1){//退现金 2.返优惠劵
			if($('#tkje').attr("display")=="none"){
				$('#tkje').css("display","none");
				$('#fjje').css("display","");
			}else{
				$('#tkje').css("display","");
				$('#fjje').css("display","none");
			}
		}else{
			if($('#fjje').attr("display")=="none"){
				$('#tkje').css("display","");
				$('#fjje').css("display","none");
			}else{
				$('#tkje').css("display","none");
				$('#fjje').css("display","");
			}
		}
	 }
	 
	 //扣款确认
	 function sure(){
		var forms= serialize('debit');//扣款表单
		if(forms.refund_party==null||forms.refund_party==""){
			layer.msg("refund method cannot be empty");
			return;
		}
		if(forms.refund_party==1){//
			forms.refund_amout=$('#refund_amout').val();
		}else{//返劵金额
			forms.refund_amout=$('#refund_amout1').val();
		}
		if(forms.refund_amout==null||forms.refund_amout==""){
			layer.msg("deduction account cannot be empty");
			return;
		}
		var customer_ip =returnCitySN["cip"]
		forms.customer_ip=customer_ip;
		var data=JSON.stringify(forms);
		console.log("forms="+data);
		var tkLoadIndex=layer.load(1, {
			  shade: [0.1,'#fff'] //0.1透明度的白色背景
		});
		$('#tkLoadIndex').val(tkLoadIndex);
		 $.ajax({
				type:'post',
				url:"sugFeedback/refund",
				 data: data,
		         contentType:"application/json;charset=UTF-8", 
		         dataType:"json",
		         success: function(data){  
		        	  layer.close(tkLoadIndex);
		        	 if(data.code==200){
		        		 layer.closeAll();
		        		 doQuery1('demo-table',queryParams());
		        	       }else{
		        	    	   cacel(); 
		        	    	    layer.msg(data.msg);
		        	       }
		         }
			});
	 }
	 
	//正则验证电话号码
	 function reg(id){
	 	var text=$('#'+id+'').val();
	 		 if(parseInt(text)<=0){
	 			$('#'+id+'').css("border-color","#FF0000")
	 		 }else{
	 			$('#'+id+'').css("border-color","#ccc")
	 		 }
	 	}
	 
	 //更新订单状态为不扣款 
	 function noDeductions(id){
		 $.ajax({
				type:'get',
				url:"sugFeedback/driverNoDeductions?id="+id,
		         success: function(data){   
		        	 if(data.code==200){
		        		 layer.closeAll();
		        		 doQuery1('demo-table',queryParams());
		        	       }else{
		        	    	    layer.msg(data.msg);
		        	       }
		         }
			});
	 }
function see(index){
		var title="Feedback details";	
		 var local = JSON.parse(sessionStorage.getItem('local'+index));
		 var msgtitle = local.msgtitle;
		 var msgcontent = local.msgcontent;
		 var account = local.account;
		 var replContent=local.replContent;
		 var img = local.imgs;var imgs="";
		 var id=local.id;
		 if(img!=null&&img!=""){
			 var im = img.split(",");
			for(var i in im){
				 imgs+="<img style='width:80px;height:80px;margin-left:10px' src='"+im[i]+"'/>";
			}
		 }
		 
	layer.open({
		  type: 1,
		  title: title,
		  skin: 'layui-layer-rim', //加上边框
		  area: ['620px', '380px'], //宽高
		  content: ' <form id="add" ><table style="margin-left:10px">'+
		           '  <tr class="padtr"><td class="pad" >Title(标题):</td> '+
            '<td>'+msgtitle+'</td>'+
            '</tr>'+
            '  <tr class="padtr"><td class="pad" >Content(内容):</td> '+
            '<td><input type=\'hidden\' id=\"revertid\"  value="'+id+'"/><span>'+msgcontent+'</span></td>'+
            '</tr>'+
            '  <tr class="padtr"><td class="pad" >Photo(图片):</td> '+
            '<td>'+imgs+'</td>'+
            '</tr>'+
            '  <tr class="padtr"><td class="pad" >Account(账号):</td> '+
            '<td><input type="text" id="account" name="account" value="'+account+'"/></td>'+
            '</tr>'+
            '  <tr class="padtr"><td class="pad" >Reply content():</td> '+
            '<td><input type="text" id="replContent" name="replContent" value="'+replContent+'"/></td>'+
            '</tr>'+
            '  <tr class="padtr"><td class="pad">Status(处理状态):</td> '+
            '<td><select id=\'msgstats\' class="form-control" ><option value=\'0\'>Not Complete</option><option value=\'3\'>Complete</option></select></td>'+
            '</tr>'+
            ' <tr align="center" class="padtr"><td colspan="5">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
            ' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
            ' <button type="button"  onclick="cacel()"class="btn  btn1" style="border: 1px solid;">&nbsp;Cancel&nbsp;&nbsp;</button>'+
            '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+
            '<button type="button" onclick="revertSave()" class="btn btn-info btn1">&nbsp;&nbsp;Save&nbsp;&nbsp;</button></td></tr></table></form>'
		});
}
	function cacel(){
		var tkIndex=$('#tkIndex').val();
		 if(tkIndex!=undefined){
			 layer.close(tkIndex);
		 }else{
			 layer.closeAll();
		 }
	}
//回复提交
function revertSave(){
	var id = $('#revertid').val();
	var account = $('#account').val();
	var replContent = $('#replContent').val();
	var data={"id":id,"account":account,"replContent":replContent};
	$.ajax({
		type:'post',
		url:"sugFeedback/addOrUpdate",
		 data: JSON.stringify(data),
         contentType:"application/json;charset=UTF-8", 
         dataType:"json",
         success: function(data){   
        	 if(data.code==200){
        		 layer.closeAll();
        		 doQuery1('demo-table',queryParams());
        	       }else{
        	    	    layer.msg(data.msg);
        	       }
         }
	});
}
	function pop(id,status){
		var check1="";var check2="";
		if(status==0){
			check1="checked";
		}else{
			check2="checked";
		}
		var str = "";
		 str+="<form class=\"form-horizontal\">"
			+"<div class=\"form-group\"><label  class=\"col-sm-4 control-label\">Status(处理状态)</label>"
			+"<div class='col-sm-3'>"
			+"<select id='msgstat1' class=\"form-control\" >"
			+"<option value='0' "+check1+">Not Complete</option><option value='3' "+check2+">Complete</option></select>"
			+"<input type='hidden' id=\"id\"  value='"+id+"'/></div></div>"
			+"<div class=\"form-group\"><label  class=\"col-sm-4 control-label\">Notes(备注)</label><div class='col-sm-3'>"
			+"<textarea rows=\"3\" cols=\"20\" id=\"remark\"></textarea>"
			+"</div></div>"
			+"<div class=\"form-group\" style=\"padding-left: 10%\">"
			+" <button  onclick=\"save()\" class=\"btn btn-info\"style=\"width: 200px\">Save</button><button  onclick=\"cacel()\" style=\"width: 200px;margin-left:10px\" class=\"btn btn-info\">Cancel</button></div></form >";
			layer.open({
				  type: 1,
				  title: "Update status",
				  skin: 'layui-layer-rim', //加上边框
				  area: ['540px', '340px'], //宽高
				  content: str
				});
			$('#msgstat').val(status);
	}
	
	
	//
	function save(){
		var id=$('#id').val();
		var remark=$("#remark").val();
		var msgstat=$('#msgstat1').val();
		var data={"id":id,"remark":remark,"msgstat":msgstat};
		$.ajax({
			type:'post',
			url:"sugFeedback/addOrUpdate",
			 data: JSON.stringify(data),
             contentType:"application/json;charset=UTF-8", 
             dataType:"json",
             success: function(data){   
            	 if(data.code==200){
            		 doQuery1('demo-table',queryParams());
            	       }else{
            	    	    layer.msg(data.msg);
            	       }
             }
		});
	}
	
	
	function queryParams(params) {
		 console.log(params);  
	    var param = {
	    		startTime:$('#startTime').val(), 
	    		endTime:$('#endTime').val(),
	    		msgstat:$('#msgstat').val(),
	    		replystat:$('#replystat').val(),
	    		orderId:1,
	    		pageNo : this.pageNumber,
	        pageSize : this.pageSize
	    }	
	    return param;
	} 
	function queryParams1(){
		 var param = {
				 startTime:$('#startTime').val(), 
		    		endTime:$('#endTime').val(),
		    		msgstat:$('#msgstat').val(),
		    		replystat:$('#replystat').val(),
		    		orderId:1,
		        pageNo : 1,
		        pageSize : this.pageSize
		    }	
		    return param;
	}
	</script>
</html>


